//
// Created by gogoqiu on 2021/8/22.
//

#include "PreferenceScreen.h"

//RecreateList(wxLC_REPORT | wxLC_SINGLE_SEL);

// ----------------------------------------------------------------------------
// changing list ctrl modes
// ----------------------------------------------------------------------------
/*
wxBEGIN_EVENT_TABLE(PreferenceListCtrl, wxListCtrl)
    EVT_LIST_ITEM_SELECTED(LIST_CTRL, PreferenceListCtrl::OnSelected)
    //EVT_LIST_ITEM_DESELECTED(LIST_CTRL, PreferenceListCtrl::OnDeselected)
    EVT_LIST_KEY_DOWN(LIST_CTRL, PreferenceListCtrl::OnListKeyDown)
    EVT_LIST_ITEM_ACTIVATED(LIST_CTRL, PreferenceListCtrl::OnActivated)
    EVT_LIST_ITEM_FOCUSED(LIST_CTRL, PreferenceListCtrl::OnFocused)

    EVT_RIGHT_DOWN(PreferenceListCtrl::OnRightClick)
wxEND_EVENT_TABLE()

void PreferenceListCtrl::InsertItemInReportView(int i) {

}

void PreferenceListCtrl::OnSelected(wxListEvent &event) {

}

void PreferenceListCtrl::OnListKeyDown(wxListEvent &event) {

}

void PreferenceListCtrl::OnActivated(wxListEvent &event) {

}

void PreferenceListCtrl::OnFocused(wxListEvent &event) {

}

void PreferenceListCtrl::OnRightClick(wxMouseEvent& event){

}

wxBEGIN_EVENT_TABLE(PreferenceFrame, wxFrame)
                EVT_MENU(LIST_QUIT, PreferenceFrame::OnQuit)
                EVT_MENU(LIST_LIST_VIEW, PreferenceFrame::OnListView)
                EVT_MENU(LIST_REPORT_VIEW, PreferenceFrame::OnReportView)
wxEND_EVENT_TABLE()

//
PreferenceFrame::PreferenceFrame(const wxString& title){
    m_listCtrl = nullptr;
    //m_logWindow = NULL;
    //m_smallVirtual = false;
    m_imageListSmall = nullptr;
    m_numListItems = 10;

    // Give it an icon
    //SetIcon(wxIcon(sample));

    // Make an image list containing large icons
    /*
    m_imageListNormal = new wxImageList(32, 32, true);
    m_imageListSmall = new wxImageList(16, 16, true);

    m_imageListNormal->Add( wxIcon("icon1", wxBITMAP_TYPE_ICO_RESOURCE) );
    m_imageListNormal->Add( wxIcon("icon2", wxBITMAP_TYPE_ICO_RESOURCE) );
    m_imageListNormal->Add( wxIcon("icon3", wxBITMAP_TYPE_ICO_RESOURCE) );
    m_imageListNormal->Add( wxIcon("icon4", wxBITMAP_TYPE_ICO_RESOURCE) );
    m_imageListNormal->Add( wxIcon("icon5", wxBITMAP_TYPE_ICO_RESOURCE) );
    m_imageListNormal->Add( wxIcon("icon6", wxBITMAP_TYPE_ICO_RESOURCE) );
    m_imageListNormal->Add( wxIcon("icon7", wxBITMAP_TYPE_ICO_RESOURCE) );
    m_imageListNormal->Add( wxIcon("icon8", wxBITMAP_TYPE_ICO_RESOURCE) );
    m_imageListNormal->Add( wxIcon("icon9", wxBITMAP_TYPE_ICO_RESOURCE) );

    m_imageListSmall->Add( wxIcon("iconSmall", wxBITMAP_TYPE_ICO_RESOURCE) );
    *//*
    m_panel = new wxPanel(this, wxID_ANY);

    //ReCreateList(wxLC_REPORT | wxLC_SINGLE_SEL);
    //wxListCtrl* const old = m_listCtrl;
    m_listCtrl = new PreferenceListCtrl(m_panel, LIST_CTRL,
                                        wxDefaultPosition, wxDefaultSize,
                                wxLC_REPORT | wxLC_SINGLE_SEL | wxBORDER_THEME | wxLC_EDIT_LABELS);
    InitWithReportItems();

    CreateStatusBar();

    auto* const sizer = new wxBoxSizer(wxVERTICAL);

    wxMenuBar* const mb = GetMenuBar();
    if ( mb )
        m_listCtrl->EnableBellOnNoMatch(mb->IsChecked(LIST_TOGGLE_BELL));

    mb->Check(LIST_ROW_LINES, false);

    sizer->Add(m_listCtrl, wxSizerFlags(2).Expand().Border());
    //sizer->Add(m_logWindow, wxSizerFlags(1).Expand().Border());
    m_panel->SetSizer(sizer);

    SetClientSize(m_panel->GetBestSize());
}
*/
/**
 * how to create a list
 */
 /*
void PreferenceFrame::InitWithReportItems()
{
    m_listCtrl->SetImageList(m_imageListSmall, wxIMAGE_LIST_SMALL);

    // note that under MSW for SetColumnWidth() to work we need to create the
    // items with images initially even if we specify dummy image id
    wxListItem itemCol;
    itemCol.SetText("Column 1");
    itemCol.SetImage(-1);
    m_listCtrl->InsertColumn(0, itemCol);

    //
    itemCol.SetText("Column 2 (auto size excluding header)");
    itemCol.SetAlign(wxLIST_FORMAT_CENTRE);
    m_listCtrl->InsertColumn(1, itemCol);

    //
    itemCol.SetText("Column 3 (auto size including header)");
    itemCol.SetAlign(wxLIST_FORMAT_RIGHT);
    m_listCtrl->InsertColumn(2, itemCol);

    // to speed up inserting we hide the control temporarily
    m_listCtrl->Hide();

    wxStopWatch sw;

    for ( int i = 0; i < m_numListItems; i++ ){
        //
        m_listCtrl->InsertItemInReportView(i);
    }
    m_listCtrl->Show();

    // we leave all mask fields to 0 and only change the colour
    wxListItem item;
    item.m_itemId = 0;
    item.SetTextColour(*wxRED);
    m_listCtrl->SetItem( item );

    item.m_itemId = 2;
    item.SetTextColour(*wxGREEN);
    m_listCtrl->SetItem( item );

    item.m_itemId = 4;
    item.SetTextColour(*wxLIGHT_GREY);
    item.SetFont(*wxITALIC_FONT);
    item.SetBackgroundColour(*wxRED);
    m_listCtrl->SetItem( item );

    m_listCtrl->SetTextColour(*wxBLUE);

    // Set images in columns
    m_listCtrl->SetItemColumnImage(1, 1, 0);

    wxListItem info;
    info.SetImage(0);
    info.SetId(3);
    info.SetColumn(2);
    m_listCtrl->SetItem(info);

    // test SetItemFont too
    m_listCtrl->SetItemFont(0, *wxITALIC_FONT);

    m_listCtrl->SetColumnWidth( 0, wxLIST_AUTOSIZE );
    m_listCtrl->SetColumnWidth( 1, wxLIST_AUTOSIZE );
    m_listCtrl->SetColumnWidth( 2, wxLIST_AUTOSIZE_USEHEADER );
}

void PreferenceFrame::OnQuit(wxCommandEvent &event) {

}

void PreferenceFrame::OnListView(wxCommandEvent &event) {

}

void PreferenceFrame::OnReportView(wxCommandEvent &event) {

}

PreferenceFrame::~PreferenceFrame(){
    int a = 9;

}*/